#include "Timer.h"

Timer::Timer()
{
#ifdef _WIN32
    LARGE_INTEGER i;
    QueryPerformanceFrequency(&i);
    frequency = i.QuadPart;
#else
    frequency = 1000000;
#endif
	ticks = getTicks();
}

Timer::~Timer()
{
}

int64 Timer::getTicks()
{
#ifdef _WIN32
    LARGE_INTEGER i;
    QueryPerformanceCounter(&i);
    return i.QuadPart;
#else
    timeval tp;
    gettimeofday(&tp, NULL);
    return (int64)((int64)tp.tv_sec*1000000 + tp.tv_usec);
#endif
}

void Timer::resetReference()
{
	ticks = getTicks();
}

float Timer::secondsSinceReference()
{
	return (float)(getTicks() - ticks)/(float)frequency;
}